Skip to content

[AGE-2759] Add a partial session_event index for feature-signal event types - #1337

Merged
heerambavi1998 merged 9 commits into
mainfrom
rutvij/age-2759_1
Nov 11, 2026
Merged

heerambavi1998 merged 9 commits into
mainfrom
rutvij/age-2759_1

Conversation

@rutvij-menavlikar

@rutvij-menavlikar rutvij-menavlikar commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Per-session lookups that filter on sandbox.created, model.message, and thread.created events currently have to read and parse the payload of every event in the session to check its type. This PR adds a partial index on session_event (session_id) restricted to those three event types, so those lookups touch only the relevant rows.

The migration uses IF NOT EXISTS, so large deployments can pre-create the index with CREATE INDEX CONCURRENTLY before migrating. The in-migration build is transactional and blocks event inserts while it runs.

Linear: AGE-2759

Changes

  • Add SESSION_EVENT_FEATURE_TYPE_IDX (session_event_feature_type_idx) to packages/trueforge/src/db/indexes.ts.
  • Add migration 20261111_000003_session_event_feature_type_idx.ts:
    • up creates the partial index ON session_event (session_id) WHERE event->>'type' IN ('sandbox.created', 'model.message', 'thread.created') using IF NOT EXISTS.
    • down drops it with IF EXISTS.
    • Both set lock_timeout = '5s' (SET LOCAL) so the migration fails fast instead of queueing behind long locks.
  • Add a patch changeset for @truefoundry/trueforge.

Risk / rollout

session_event is a high-write table. For large deployments, pre-create the index CONCURRENTLY before running the migration, which then becomes a no-op. Rollback is a plain DROP INDEX.

How was this tested?

Checklist

  • I have read the contributing guidelines
  • pnpm build, pnpm test, pnpm typecheck, pnpm lint:ci, and pnpm format:check pass locally
  • Tests added/updated where it makes sense
  • No hand-edits to generated code (packages/trueforge-sdk, python/trueforge_sdk, .github/fern/openapi/openapi.json, docs/openapi.json) — fork PRs omit SDK regen; maintainers regenerate after merge
  • Docs / .env.example updated if configuration or behavior changed (N/A: no config or behavior docs affected)

Note

Medium Risk
Index creation on the high-write session_event table can block inserts during migration unless the index is pre-built CONCURRENTLY; rollout behavior is unchanged after the index exists.

Overview
Adds a Postgres expression index on session_event for event->>'type', so filters on event type can use the index instead of parsing every JSON payload on scan.

Introduces SESSION_EVENT_TYPE_IDX and migration 20261111_000003_session_event_type_idx (CREATE INDEX IF NOT EXISTS / DROP INDEX IF EXISTS) with SET LOCAL lock_timeout = '5s' so migrations fail fast under lock contention. Large deployments can pre-create the index with CONCURRENTLY so the migration is a no-op. Includes a patch changeset for @truefoundry/trueforge.

Reviewed by Cursor Bugbot for commit 5a0d90e. Bugbot is set up for automated code reviews on this repo. Configure here.

… types

Analytics feature adoption reads only sandbox.created, model.message, and
thread.created events per session. Without an index it parses every event
payload to check its type. IF NOT EXISTS lets large deployments pre-create the
index CONCURRENTLY, since the migration's transactional build blocks event
inserts while it runs.
@changeset-bot

changeset-bot Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 5a0d90e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@truefoundry/trueforge Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@veria-ai

veria-ai Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

PR overview

No security issues were found in this pull request.

Reviews

@cursor cursor Bot changed the title [AGE-2759] Add a partial session_event index for feature-signal event… [AGE-2759] Add a partial session_event index for feature-signal event types Nov 11, 2026
rutvij-menavlikar and others added 5 commits November 11, 2026 16:05
Co-authored-by: Cursor <cursoragent@cursor.com>
…and thread.created

model.message is no longer read by its consumer, so it is dropped from the
index predicate. The remaining types are a small fraction of events.
Replace the partial index on two event types with an expression index on
event->>'type', so any query filtering events by type can use it.
@heerambavi1998
heerambavi1998 enabled auto-merge (squash) November 11, 2026 12:04
@heerambavi1998
heerambavi1998 merged commit 5ec1a26 into main Nov 11, 2026
15 of 16 checks passed
@heerambavi1998
heerambavi1998 deleted the rutvij/age-2759_1 branch November 11, 2026 12:11
truefoundry-saas added a commit that referenced this pull request Nov 11, 2026
* [AGE-2759] Add a partial session_event index for feature-signal event types (#1337)

* refactor: update SERVER_URL handling in controller configuration (#1345)

* refactor: update SERVER_URL handling in controller configuration

* refactor: simplify comments for SERVER_URL in controller configuration
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants